package com.woniuxy.house.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.entity.ResponseResult;
import com.woniuxy.entity.house.Comments;
import com.woniuxy.house.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liangyu
 * @since 2021-03-19
 */
@Api(tags = "楼盘评论", description = "管理所有楼盘的评论")
@RestController
@RequestMapping("/house/comments")
public class CommentsController {

    @Resource
    private CommentsService commentsService;


    /**
     * 通过楼盘id查询评论
     *
     * @param id
     * @param current
     * @param size
     * @return
     */
    @ApiOperation("通过楼盘id查询评论")
    @GetMapping("/findById")
    public ResponseResult<Page<Comments>> findComments(int id, int current, int size) {
        Page<Comments> commentsList = commentsService.findByBid(id, current, size);
        if (commentsList != null) {
            return new ResponseResult<>(commentsList);
        } else {
            return new ResponseResult<>(500, "FAIl");
        }
    }

    /**
     * 删除经纪人评论
     *
     * @param id 评论id
     * @return
     */
    @ApiOperation("根据经纪人id删除评论")
    @PostMapping("/delete")
    public ResponseResult deleteComments(int id) {
        if (commentsService.deleteComments(id)) {
            return ResponseResult.SUCCESS;
        } else {
            return ResponseResult.FAIL;
        }
    }

    /**
     * 新增经纪人评论
     *
     * @param comments 评论
     * @return
     */
    @ApiOperation("新增经纪人id删除评论")
    @PostMapping("/add")
    public ResponseResult insertComments(Comments comments) {
        //需要先获取经纪人信息
        //经纪人id为1
        int id = 1;
        comments.setId(id);
        System.out.println(comments);
        System.out.println(LocalDate.now());
        if (commentsService.insertComments(comments)) {
            return ResponseResult.SUCCESS;
        } else {
            return ResponseResult.FAIL;
        }
    }

//    /**想用elacsearch
//     * 违规评论检索
//     * @param content
//     * @return
//     */
//    @GetMapping("/findViolations")
//    public ResponseResult<List<Comments>> findViolations(String content){
//
//    }

}

